/*
 * Copyright (c) 2021-2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define LOG_TAG "main"

#include <iostream>
#include <memory>
#ifdef OHOS_LITE
#include "hiplayer.h"
#else
#include "i_engine_factory.h"

#ifdef __cplusplus
extern "C" {
#endif
__attribute__((visibility("default"))) OHOS::Media::IEngineFactory* CreateEngineFactory();
#ifdef __cplusplus
}
#endif

#endif
using namespace OHOS::Media;
enum class MusicClass { MP3, AAC_LC, AAC_HE, AAC_HE2, AAC_LOAS, M4A, WAV, AVS3DA };

std::string GetMusicUri(MusicClass musicClass)
{
    std::string uri = RESOURCE_DIR "/";
    switch (musicClass) {
        case MusicClass::MP3:
            uri += "MP3/MP3_LONG_48000_32.mp3";
            break;
        case MusicClass::AAC_LC:
            uri += "AAC/AAC_LONG_48000_32.aac";
            break;
        case MusicClass::AAC_HE:
            uri += "AAC/AAC_LONG_48000_32.aac";
            break;
        case MusicClass::AAC_HE2:
            uri += "AAC/AAC_LONG_48000_32.aac";
            break;
        case MusicClass::AAC_LOAS:
            uri += "AAC/AAC_LONG_48000_32.aac";
            break;
        case MusicClass::M4A:
            uri += "M4A/MPEG-4_48000_32_LONG.m4a";
            break;
        case MusicClass::WAV:
            uri += "WAV/vorbis_48000_32_SHORT.wav";
            break;
        case MusicClass::AVS3DA:
            uri += "AVS3DA/21_Bluebirds_ADM_bed5.1.2_obj2_ADM.mp4";
            // uri += "AVS3DA/21_ANYTHING_YOU_WANT_ADM_bed5.1.2_obj2_ADM.mp4";
            break;
        default:
            uri += "MP3/MP3_LONG_48000_32.mp3";
            break;
    }
    return uri;
}

#ifdef VIDEO_SUPPORT
enum class VideoClass { H264 };

std::string GetVideoUri(VideoClass videoClass)
{
    std::string uri = "MP4/11_AVC_640x480_25.000fps.mp4";
    switch (videoClass) {
        case VideoClass::H264:
            break;
        default:
            break;
    }
    return uri;
}
#endif

int main(int argc, char* argv[])
{
#ifdef OHOS_LITE
    auto player = OHOS::Media::CreateHiPlayer();
    player->Init();
#ifdef VIDEO_SUPPORT
    OHOS::Media::Source source(GetVideoUri(VideoClass::H264));
#else
    OHOS::Media::Source source(GetMusicUri(MusicClass::MP3));
#endif
    player->SetSource(source);
    player->SetLoop(true);
#else
    auto engineFactory = std::unique_ptr<OHOS::Media::IEngineFactory>(CreateEngineFactory());
    auto player = engineFactory->CreatePlayerEngine();
    player->SetSource(GetMusicUri(MusicClass::MP3));
    player->SetLooping(true);
#endif
    player->Prepare();
    player->Play();
    std::cin.get();
    std::cout << "Main Puase called." << std::endl;
    player->Pause();
    std::cin.get();
    player->Stop();
    //    std::cin.get();
    return 0;
}
